<?php

/*** 

BBCode -> HTML

[mail]test@test.de[/mail] -> <a href="mailto:test@test.de>test@test.de</a>
[url]www.test.de[/url] -> <a href="www.test.de" target="_blank">www.test.de</a>
[url="www.test.de"]test[/url] -> <a href="www.test.de" target="_blank">test</a>
[b]test[/b] -> <b>test</b>
[small]test[/small] -> <small>test</small>
[i]test[/i] -> <i>test</i>
[code]if (true)[/code] -> <pre><code>if (true)</code></pre>
[u]test[/u] -> <u>test</u>
[center]test[/center] -> <center>test</center>
[color=Hashcode/Farbwert] test[/color]-> <span style="color:Hashcode/Farbwert">test</span>
[quote]test[/quote] -> <div class="zitat">test</div>
[img]http://wwww.pfad.zu.einem.bild.jpg[/img] -> <img src="http://wwww.pfad.zu.einem.bild.jpg" border="0" alt="bild" /> 

***/

// Ersetzungen der Erlaubten BBCodes in Kommentaren und News
function ersetzeBBCodes($text) {
	$text = str_replace('www.','http://www.',$text);
	//$text = eregi_replace("\[mail\]([^\[]+)\[/mail\]","<a href=\"mailto:\\1\">\\1</a>",$text);
	//$text = eregi_replace("\[url\]([^\[]+)\[/url\]","<a href=\"\\1\" target=\"_blank\">\\1</a>",$text);
	//$text = eregi_replace("\[url=\"([^\"]+)\"]([^\[]+)\[/url\]","<a href=\"\\1\"target=\"_blank\">\\2</a>",$text); 		
	$text = preg_replace("/\[b\](.*?)\[\/b\]/si","<b>\\1</b>", $text);
	$text = preg_replace("/\[small\](.*?)\[\/small\]/si","<small>\\1</small>", $text);
	$text = preg_replace("/\[i\](.*?)\[\/i\]/si","<i>\\1</i>", $text);
	$text = preg_replace("/\[code\](.*?)\[\/code\]/si","<pre><code>\\1</code></pre>", $text);
	$text = preg_replace("/\[u\](.*?)\[\/u\]/si","<u>\\1</u>", $text);
	$text = preg_replace("/\[url=http:\/\/(.*?)\](.*?)\[\/url\]/si","<a href=\"http://\\1\" target=\"_blank\">\\2</a>", $text);
	$text = preg_replace("/\[center\](.*?)\[\/center\]/si","<center>\\1</center>", $text); 
	$text = preg_replace("/\[color=(.*)\](.*)\[\/color\]/Usi", "<span style=\"color:\\1;\">\\2</span>", $text);
	while(preg_match('/\[quote\](.*)\[\/quote\]/Uis', $text)) {
		$quote_start = "<div class=\"zitat\">\n";
		$quote_end = "</div>";
		$text = preg_replace("/\[quote](.*)\[\/quote\]/Uis", $quote_start."\\1".$quote_end, $text);
	} 
	return $text;
}

// Bilder BBCode  (darf nur bei News verwendet werden, dewswegen einzeldn)
function ersetzeBilder($eintrag) {
	$eintrag = preg_replace("/\[img\](.*?)\[\/img\]/si","<img src=\"\\1\" border=\"0\" alt=\"bild\" \/>", $eintrag);
	return $eintrag;
}

// Entfernt alle BBCodes
function bbCodesEntfernen($text) {
	$text = preg_replace("(\[b\])","",$text);
	$text = preg_replace("(\[/b\])","",$text);
	$text = preg_replace("(\[i\])","",$text);
	$text = preg_replace("(\[/i\])","",$text);
	$text = preg_replace("(\[u\])","",$text);
	$text = preg_replace("(\[/u\])","",$text);
	$text = preg_replace("(\[img\])","",$text);
	$text = preg_replace("(\[/img\])","",$text);
	$text = preg_replace("(\[url\])","",$text);
	$text = preg_replace("(\[/url\])","",$text);
	$text = preg_replace("(\[mail\])","",$text);
	$text = preg_replace("(\[/mail\])","",$text);
	$text = preg_replace("(\[code\])","",$text);
	$text = preg_replace("(\[/code\])","",$text);
	$text = preg_replace("(\[center\])","",$text);
	$text = preg_replace("(\[/center\])","",$text);
	$text = preg_replace("(\[quote\])","",$text);
	$text = preg_replace("(\[/quote\])","",$text);
	$text = preg_replace("(\[u\])","",$text);
	$text = preg_replace("(\[small\])","",$text);
	$text = preg_replace("(\[/small\])","",$text);
	$text = preg_replace("/\[url=http:\/\/(.*?)\](.*?)\[\/url\]/si","\\2 : \\1 ", $text);
	$text = preg_replace("/\[color=(.*)\](.*)\[\/color\]/Usi", "\\2", $text);
	return $text;
}


?>